package com.mid;

/**
 * Created by Lxk on 2019/6/7.
 */
public class Solution328 {

    public ListNode oddEvenList(ListNode head) {
        if(head == null){
            return null;
        }
        ListNode cur = head;
        ListNode odd = new ListNode(1);
        ListNode curOdd = odd;
        ListNode even = new ListNode(0);
        ListNode curEven = even;
        boolean isOdd = true;
        while(cur!=null){
            if(isOdd){
                curOdd.next = cur;
                curOdd = curOdd.next;
                cur = cur.next;
                curOdd.next = null;
                isOdd = false;
            }else{
                curEven.next = cur;
                curEven = curEven.next;
                cur = cur.next;
                curEven.next = null;
                isOdd = true;
            }
        }
        curOdd.next = even.next;
        return odd.next;
    }

}
